import HomeView from "../views/HomeView.vue";
import { getToken } from "@/utils/token";
const routes = [
  {
    path: "/",
    redirect: "/home",
    component: HomeView,
    children: [
      {
        path: "home",
        component: () => import("@/views/Home"),
        meta: {
          isRecord: true,
          scrollTop: 0, // 保存首页离开时, 滚动条位置
          active: 0
        }
      },
      {
        path: "chat",
        component: () => import("@/views/Chat"),
        meta: {
          active:1
        },
      },
      {
        path: "user",
        component: () => import("@/views/User"),
        meta:{
          active:2
        }
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/Login.vue"),
    beforeEnter(to, from, next) {
      if (getToken()?.length > 0) {
        // vuex里有token(代表登录过, 但是一定要注意过期和主动退出要先清除vuex和本地的token, 让其跳转登录页)
        return next(false);
      }
      next();
    },
  },
  {
    path: "/search",
    component: () => import("@/views/Search"),
  },
  {
    path: "/search/:keywords",
    component: () => import("@/views/Search/SearchResult.vue"),
  },
  {
    path: "/article_detail",
    component: () => import("@/views/ArticleDetail"),
  },
  {
    path: "/user_edit",
    component: () => import("@/views/User/UserEdit.vue"),
  },
  {
    path: "/articleColle",
    component: () => import("@/views/User/ArticleCollections.vue"),
  },
];
export default routes;
